﻿using UnityEngine;
using System.Collections;
using DICE_GS;

public class CharacterSummonManager : MonoBehaviour {
	public MyUnitCard cardObject;

	public GameObject colliderObject;
	
	private static CharacterSummonManager _singleton;
	public static CharacterSummonManager singleton
	{
		get
		{
			if( _singleton == null )
				_singleton = new CharacterSummonManager();
			
			return _singleton;
		}
	}
	
	// Use this for initialization
    //TweenAlpha twAlpha;
	TweenPosition twPosition;
	private Vector3 prevCardPosition;
	bool isRare = false;

    public static bool isSummonFlow = true;   //진화에서 사용
	public static int characterId = 0;

	void Awake () {
        if (CSceneManager.m_Scene == SCENE.SummonRareScene) isRare = true;
	}
	
	void Start()
	{
        LoadingWindow.window.HideLoading();	
//		if( isRare )
//			RestAPI.singleton.GetCashGachaInfo(RestReturnCallback);
//		else
//			RestAPI.singleton.GetNormalGachaInfo(RestReturnCallback);	

		int unitLevel = 1;
		CUnitData unitData = CUnitDataManager.Instance.GetUnitData(characterId);
        
		CUnitAbilityItem plusAbility = CUnitAbilityDataManager.Instance.GetUnitAbilityData(unitLevel + "_" + unitData.unit_class);
		cardObject.SetCardInfo(0, unitLevel, unitData, plusAbility);
	}
	

	// Update is called once per frame
	void Update () {
	
	}
	
		
	int receivedUnitId=0;
	void RestReturnCallback(Hashtable returnData)
	{
		Debug.LogError("returnData : " + returnData["protocol"].ToString());
        LoadingWindow.window.HideLoading();
		receivedUnitId = int.Parse(returnData["UnitId"].ToString());
		CharacterSummonResultManager.summonedUnitId = receivedUnitId;
		CUnitData tmpUnitData = CUnitDataManager.Instance.GetUnitData(receivedUnitId);
		
        //if( !isRare )
        //    StartCommonEffect();
        //else
        //    StartRareEffect();
	}
	
	void OnCLoseButtonClick()
	{
		Debug.LogError("CloseButton Clicked!");
        if (isSummonFlow)
        {
            CSceneManager c = GameObject.FindObjectOfType(typeof(CSceneManager)) as CSceneManager;
            c.GoToSummonMenuScene();
        }
        else
        {
            CSceneManager.manager.GoToUnitPowerUpScene();

            isSummonFlow = true;    // 기본이 소환씬
        }
	}

	
	public void EnableCollider()
	{	
		colliderObject.collider.enabled = true;
	}
}
